package com.matt.foundation.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;

import java.util.List;

@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
public class StatusResponse {

    @JsonProperty("code")
    @NonNull
    private String code;

    @JsonProperty("msg")
    private String massage;

    @JsonProperty("data")
    private Object data;



    private static final StatusResponse EMPTY_SUCCESS = of(ErrorCode.SUCCESSFUL, "successful", null);
    private static final StatusResponse ERR_UNDEFINED = of(ErrorCode.UNDEFINED, "undefined",null);

    @JsonCreator
    public static StatusResponse of(
            @JsonProperty(value = "code", required = true) String code,
            @JsonProperty(value = "msg") String massage,
            @JsonProperty("data") Object data) {
        return new StatusResponse(code,massage, data);
    }

    public static StatusResponse success() {
        return EMPTY_SUCCESS;
    }

    public static StatusResponse undefined() {
        return ERR_UNDEFINED;
    }

    public static StatusResponse error(String code, String massage) {
        return of(code, massage, null);
    }

//    public static StatusResponse error(ExceptionConstant.ErrorCode errorCode) {
//        return mergeOf(errorCode.codeOf(), errorCode.valueOf(), null);
//    }


    public static StatusResponse success(Object data) {
        return of(ErrorCode.SUCCESSFUL,"successful", data);
    }




}

